package com.xhtt.modules.task.schedule;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xhtt.modules.cfg.entity.CfgWarnShip;
import com.xhtt.modules.cfg.entity.CfgWarnSj;
import com.xhtt.modules.cfg.entity.CfgWarnTask;
import com.xhtt.modules.cfg.service.CfgTaskSubService;
import com.xhtt.modules.cfg.service.CfgWarnShipService;
import com.xhtt.modules.cfg.service.CfgWarnSjService;
import com.xhtt.modules.cfg.service.CfgWarnTaskService;
import com.xhtt.modules.msg.entity.MsgInfo;
import com.xhtt.modules.msg.service.MsgInfoService;
import com.xhtt.modules.sys.entity.SysUserEntity;
import com.xhtt.modules.sys.service.SysUserService;
import com.xhtt.modules.task.dao.TaskAllMapper;
import com.xhtt.modules.task.entity.TaskOperTask;
import com.xhtt.modules.task.entity.TaskPotTask;
import com.xhtt.modules.task.entity.TaskServiceTask;
import com.xhtt.modules.task.entity.TaskShipTask;
import com.xhtt.modules.task.model.alltask.LMWarnModel;
import com.xhtt.modules.task.model.alltask.LMWarnMsgModel;
import com.xhtt.modules.task.model.alltask.TaskWarnModel;
import com.xhtt.modules.task.model.alltask.TaskWarnMsgModel;
import com.xhtt.modules.task.model.lmtask.BusinessCheckModel;
import com.xhtt.modules.task.model.lmtask.TaskOperLMModel;
import com.xhtt.modules.task.model.ship.TaskOperCCRModel;
import com.xhtt.modules.task.service.TaskOperTaskService;
import com.xhtt.modules.task.service.TaskPotTaskService;
import com.xhtt.modules.task.service.TaskServiceTaskService;
import com.xhtt.modules.task.service.TaskShipTaskService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.*;

@Slf4j
@Component
public class TaskWarnMsgSchedule {
    @Autowired
    private MsgInfoService msgInfoService;
    @Autowired
    private CfgTaskSubService taskSubService;
    @Autowired
    private SysUserService sysUserService;
    @Autowired
    private CfgWarnTaskService warnTaskService;
    @Autowired
    private CfgWarnSjService sjService;
    @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
    @Autowired
    private TaskAllMapper taskAllMapper;
    @Autowired
    private TaskShipTaskService shipTaskService;
    @Autowired
    private TaskPotTaskService potTaskService;
    @Autowired
    private TaskOperTaskService operTaskService;
    @Autowired
    private TaskServiceTaskService serviceTaskService;
    @Autowired
    private CfgWarnShipService warnShipService;

    /**
     * 每2分钟扫描 一次 超时任务
     */
    @Scheduled(fixedDelay = 2 * 60 * 1000)
    public void overtimeTask() {
        List<CfgWarnTask> warnTaskList = warnTaskService.list();
        Map<String, Integer> warnMap = new HashMap<>();
        for (CfgWarnTask wt : warnTaskList) {
            //排除LM任务！这业务真是乱的一笔，想一出是一出，这业务真是边做边想的。。。。fuck
//            if (("ship".equals(wt.getPlan()) && wt.getTaskType().intValue() == 2) ||  又他妈的不排除了，卢缓缓说的
//                    ("oper".equals(wt.getPlan()) && wt.getTaskType().intValue() == 101)) {
//                continue;
//            }
            warnMap.put(wt.getPlan() + "-" + wt.getPlanType() + "-" + wt.getTaskType(), wt.getTime2());
        }
        if (warnMap.size() == 0) {
            return;
        }
        List<MsgInfo> msgInfoList = new ArrayList<>();
        MsgInfo msgInfo;
        // 查询库里的未完成的任务
        List<TaskWarnModel> warnModelList = taskAllMapper.warnTaskList();
        TaskWarnMsgModel warnMsgModel;
        List<Integer> shipTaskIds = new ArrayList<>();
        List<Integer> potTaskIds = new ArrayList<>();
        List<Integer> operTaskIds = new ArrayList<>();
        List<Integer> serviceTaskIds = new ArrayList<>();
        for (TaskWarnModel model : warnModelList) {
            String key = model.getPlan() + "-" + model.getPlanType() + "-" + model.getTaskType();
            Integer time = warnMap.get(key);
            if (null == time || time.intValue() <= 0) {
                continue;
            }
            if (("ship".equals(model.getPlan()) && model.getTaskType().intValue() == 4) ||
                    ("pot".equals(model.getPlan()) && model.getTaskType().intValue() == 2) ||
                    ("oper".equals(model.getPlan()) && model.getTaskType().intValue() == 20))//如果是ccr
            {
                String operDetail = model.getOperDetail();
                if (StringUtils.isNotEmpty(operDetail)) {
                    List<TaskOperCCRModel> ccrList = JSON.parseArray(operDetail, TaskOperCCRModel.class);//这里偷懒了全都公用 TaskOperCCRModel 反正里面结构都一样的
                    int size = ccrList.size();
                    if (size > 0) {
                        TaskOperCCRModel ccr = ccrList.get(size - 1);//取最新的一条
                        LocalDateTime startTime = ccr.getStartTime();
                        LocalDateTime finishTime = ccr.getFinishTime();
                        if (null != startTime && null == finishTime && ccr.getMsgFlag() == 0)//未发送过报警
                        {
                            LocalDateTime deadline = startTime.plusMinutes(time);
                            if (LocalDateTime.now().compareTo(deadline) > 0)//超时了
                            {
                                ccr.setMsgFlag(1);//设置成已发送

                                //更新发送状态
                                try {
                                    if ("ship".equals(model.getPlan())) {
                                        TaskShipTask t = new TaskShipTask();
                                        t.setOperDetail(JSON.toJSONString(ccrList));
                                        shipTaskService.update(t, new LambdaQueryWrapper<TaskShipTask>().eq(TaskShipTask::getId, model.getId()));
                                    } else if ("pot".equals(model.getPlan())) {
                                        TaskPotTask t = new TaskPotTask();
                                        t.setOperDetail(JSON.toJSONString(ccrList));
                                        potTaskService.update(t, new LambdaQueryWrapper<TaskPotTask>().eq(TaskPotTask::getId, model.getId()));
                                    } else if ("oper".equals(model.getPlan())) {
                                        TaskOperTask t = new TaskOperTask();
                                        t.setOperDetail(JSON.toJSONString(ccrList));
                                        operTaskService.update(t, new LambdaQueryWrapper<TaskOperTask>().eq(TaskOperTask::getId, model.getId()));
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    log.error("ccr任务更新告警状态异常");
                                }
                                send(model, msgInfoList);
                            }

                        }
                    }
                }
            } else {
                LocalDateTime startTime = model.getStartTime();
                LocalDateTime deadline = startTime.plusMinutes(time);
                if (LocalDateTime.now().compareTo(deadline) > 0)//超时了
                {
                    if ("ship".equals(model.getPlan())) {
                        shipTaskIds.add(model.getId());
                    } else if ("pot".equals(model.getPlan())) {
                        potTaskIds.add(model.getId());
                    } else if ("oper".equals(model.getPlan())) {
                        operTaskIds.add(model.getId());
                    } else if ("service".equals(model.getPlan())) {
                        serviceTaskIds.add(model.getId());
                    }
                    send(model, msgInfoList);
                }
            }
        }
        if (CollectionUtils.isNotEmpty(msgInfoList)) {
            msgInfoService.saveMsgBatch(msgInfoList);//发消息
        }
        //更新发送状态
        if (CollectionUtils.isNotEmpty(shipTaskIds)) {
            TaskShipTask t = new TaskShipTask();
            t.setMsgFlag(1);
            shipTaskService.update(t, new LambdaQueryWrapper<TaskShipTask>().in(TaskShipTask::getId, shipTaskIds));
        }
        if (CollectionUtils.isNotEmpty(potTaskIds)) {
            TaskPotTask t = new TaskPotTask();
            t.setMsgFlag(1);
            potTaskService.update(t, new LambdaQueryWrapper<TaskPotTask>().in(TaskPotTask::getId, potTaskIds));
        }
        if (CollectionUtils.isNotEmpty(operTaskIds)) {
            TaskOperTask t = new TaskOperTask();
            t.setMsgFlag(1);
            operTaskService.update(t, new LambdaQueryWrapper<TaskOperTask>().in(TaskOperTask::getId, operTaskIds));
        }
        if (CollectionUtils.isNotEmpty(serviceTaskIds)) {
            TaskServiceTask t = new TaskServiceTask();
            t.setMsgFlag(1);
            serviceTaskService.update(t, new LambdaQueryWrapper<TaskServiceTask>().in(TaskServiceTask::getId, serviceTaskIds));
        }
    }

    /**
     * 每2分钟扫描 一次 开始任务超时
     */
    @Scheduled(fixedDelay = 2 * 60 * 1000)
    public void overtimeStartTask() {
        List<CfgWarnTask> warnTaskList = warnTaskService.list();
        Map<String, Integer> warnMap = new HashMap<>();
        for (CfgWarnTask wt : warnTaskList) {
            warnMap.put(wt.getPlan() + "-" + wt.getPlanType() + "-" + wt.getTaskType(), wt.getTime1());
        }
        if (warnMap.size() == 0) {
            return;
        }
        List<MsgInfo> msgInfoList = new ArrayList<>();
        // 查询库里的未开始的任务
        List<TaskWarnModel> warnModelList = taskAllMapper.warnStartTaskList();
        List<Integer> shipTaskIds = new ArrayList<>();
        List<Integer> potTaskIds = new ArrayList<>();
        List<Integer> operTaskIds = new ArrayList<>();
        List<Integer> serviceTaskIds = new ArrayList<>();
        for (TaskWarnModel model : warnModelList) {
            String key = model.getPlan() + "-" + model.getPlanType() + "-" + model.getTaskType();
            Integer time = warnMap.get(key);
            if (null == time || time.intValue() <= 0) {
                continue;
            }
            LocalDateTime startDate = model.getStartDate();
            if (("ship".equals(model.getPlan()) && model.getTaskType().intValue() == 4) ||
                    ("pot".equals(model.getPlan()) && model.getTaskType().intValue() == 2) ||
                    ("oper".equals(model.getPlan()) && model.getTaskType().intValue() == 20))//如果是ccr
            {
                String operDetail = model.getOperDetail();
                if (StringUtils.isEmpty(operDetail) && null != startDate && model.getMsgStartFlag() == 0)//未发送过报警
                {
                    LocalDateTime deadline = startDate.plusMinutes(time);
                    if (LocalDateTime.now().compareTo(deadline) > 0)//超时了
                    {
                        //更新发送状态
                        try {
                            if ("ship".equals(model.getPlan())) {
                                TaskShipTask t = new TaskShipTask();
                                t.setMsgStartFlag(1);
                                shipTaskService.update(t, new LambdaQueryWrapper<TaskShipTask>().eq(TaskShipTask::getId, model.getId()));
                            } else if ("pot".equals(model.getPlan())) {
                                TaskPotTask t = new TaskPotTask();
                                t.setMsgStartFlag(1);
                                potTaskService.update(t, new LambdaQueryWrapper<TaskPotTask>().eq(TaskPotTask::getId, model.getId()));
                            } else if ("oper".equals(model.getPlan())) {
                                TaskOperTask t = new TaskOperTask();
                                t.setMsgStartFlag(1);
                                operTaskService.update(t, new LambdaQueryWrapper<TaskOperTask>().eq(TaskOperTask::getId, model.getId()));
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                            log.error("ccr任务更新告警状态异常");
                        }
                        startSend(model, msgInfoList);
                    }

                }
            } else {
                LocalDateTime deadline = startDate.plusMinutes(time);
                if (LocalDateTime.now().compareTo(deadline) > 0)//超时了
                {
                    if ("ship".equals(model.getPlan())) {
                        shipTaskIds.add(model.getId());
                    } else if ("service".equals(model.getPlan())) {
                        serviceTaskIds.add(model.getId());
                    } else if ("oper".equals(model.getPlan())) {
                        operTaskIds.add(model.getId());
                    } else if ("pot".equals(model.getPlan())) {
                        potTaskIds.add(model.getId());
                    }
                    startSend(model, msgInfoList);
                }
            }
        }
        if (CollectionUtils.isNotEmpty(msgInfoList)) {
            msgInfoService.saveMsgBatch(msgInfoList);//发消息
        }
        //更新发送状态
        if (CollectionUtils.isNotEmpty(shipTaskIds)) {
            TaskShipTask t = new TaskShipTask();
            t.setMsgStartFlag(1);
            shipTaskService.update(t, new LambdaQueryWrapper<TaskShipTask>().in(TaskShipTask::getId, shipTaskIds));
        }
        if (CollectionUtils.isNotEmpty(potTaskIds)) {
            TaskPotTask t = new TaskPotTask();
            t.setMsgStartFlag(1);
            potTaskService.update(t, new LambdaQueryWrapper<TaskPotTask>().in(TaskPotTask::getId, potTaskIds));
        }
        if (CollectionUtils.isNotEmpty(operTaskIds)) {
            TaskOperTask t = new TaskOperTask();
            t.setMsgStartFlag(1);
            operTaskService.update(t, new LambdaQueryWrapper<TaskOperTask>().in(TaskOperTask::getId, operTaskIds));
        }
        if (CollectionUtils.isNotEmpty(serviceTaskIds)) {
            TaskServiceTask t = new TaskServiceTask();
            t.setMsgStartFlag(1);
            serviceTaskService.update(t, new LambdaQueryWrapper<TaskServiceTask>().in(TaskServiceTask::getId, serviceTaskIds));
        }
    }

    /**
     * 商检超时
     */
    @Scheduled(fixedDelay = 2 * 60 * 1000)
    public void overtimeLM() {
        List<CfgWarnSj> warnTaskList = sjService.list();
        Map<String, Integer> warnMap = new HashMap<>();
        for (CfgWarnSj ws : warnTaskList) {
            warnMap.put(ws.getCompanyName() + "-" + ws.getProductName(), ws.getTime());
        }
        if (warnMap.size() == 0) {
            return;
        }
        List<MsgInfo> msgInfoList = new ArrayList<>();
        MsgInfo msgInfo;
        // 查询库里的未完成的LM任务
        List<LMWarnModel> warnModelList = taskAllMapper.warnLMTaskList();
        LMWarnMsgModel lmWarnMsgModel;
        for (LMWarnModel model : warnModelList) {
            String operDetail = model.getOperDetail();
            if (StringUtils.isNotEmpty(operDetail)) {
                TaskOperLMModel lmModel = JSON.parseObject(operDetail, TaskOperLMModel.class);
                List<BusinessCheckModel> businessCheckModelList = lmModel.getBusinessCheckModelList();
                if (CollectionUtils.isNotEmpty(businessCheckModelList)) {
                    for (BusinessCheckModel bcm : businessCheckModelList) {
                        String key = bcm.getCompanyName() + "-" + bcm.getProductName();
                        Integer time = warnMap.get(key);
                        if (null == time || time.intValue() <= 0) {
                            continue;
                        }

                        LocalDateTime sjddjl = bcm.getSjddjl();
                        LocalDateTime yptg = bcm.getYptg();
                        int msgFlag = bcm.getMsgFlag();
                        if (null != sjddjl && null == yptg && 0 == msgFlag)//未发送过报警
                        {
                            LocalDateTime deadline = sjddjl.plusMinutes(time);
                            if (LocalDateTime.now().compareTo(deadline) > 0)//超时了
                            {
                                bcm.setMsgFlag(1);//设置成已发送

                                //更新发送状态
                                try {
                                    if ("ship".equals(model.getPlan())) {
                                        TaskShipTask t = new TaskShipTask();
                                        t.setOperDetail(JSON.toJSONString(lmModel));
                                        shipTaskService.update(t, new LambdaQueryWrapper<TaskShipTask>().eq(TaskShipTask::getId, model.getId()));
                                    } else if ("oper".equals(model.getPlan())) {
                                        TaskOperTask t = new TaskOperTask();
                                        t.setOperDetail(JSON.toJSONString(lmModel));
                                        operTaskService.update(t, new LambdaQueryWrapper<TaskOperTask>().eq(TaskOperTask::getId, model.getId()));
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    log.error("lm任务更新告警状态异常");
                                }
                                Set<Integer> userIds = new HashSet<>();
                                SysUserEntity user = sysUserService.getTeamLeader(model.getTeamId());
                                if (null != user) {
                                    userIds.add(user.getUserId().intValue());
                                }
                                List<SysUserEntity> users = sysUserService.getDeptLeaderByTeam(model.getTeamId());//部门管理狗
                                if (CollectionUtils.isNotEmpty(users)) {
                                    users.forEach(u -> userIds.add(u.getUserId().intValue()));
                                }
                                userIds.add(model.getOperUserId());
                                String title = model.getTaskName() + ":超时未完成!";
                                lmWarnMsgModel = new LMWarnMsgModel(model.getId(), bcm.getCompanyName(), bcm.getProductName(), model.getOperUserName());
                                msgInfo = new MsgInfo("报警提示", "L/M任务", title, JSON.toJSONString(lmWarnMsgModel));
                                msgInfo.setUserIdList(userIds);
                                msgInfoList.add(msgInfo);
                            }

                        }
                    }
                }
            }
        }
        if (CollectionUtils.isNotEmpty(msgInfoList)) {
            msgInfoService.saveMsgBatch(msgInfoList);//发消息
        }
    }

    /**
     * 装卸船 lm登轮到最后接管完成 超时
     */
    @Scheduled(fixedDelay = 2 * 60 * 1000)
    public void overtimeDLJG() {
        CfgWarnShip ws = warnShipService.getOne(null);

        if (null == ws || null == ws.getTime2() || ws.getTime2().intValue() <= 0) {
            return;
        }
        Integer time = ws.getTime2();
        List<MsgInfo> msgInfoList = new ArrayList<>();
        // 查询装卸船库里的未完成的LM任务 ，未发送报警的，并且operdetail操作过的
        Map<String, Object> params = new HashMap<>();
        params.put("dljg", 1);
        List<TaskWarnModel> warnModelList = taskAllMapper.warnShipTaskList(params);
        for (TaskWarnModel model : warnModelList) {
            String operDetail = model.getOperDetail();
            TaskOperLMModel lmModel = JSON.parseObject(operDetail, TaskOperLMModel.class);
            List<BusinessCheckModel> businessCheckModelList = lmModel.getBusinessCheckModelList();
            if (null == lmModel.getLmdl())//如果登轮时间都没有 那就不用判断先
            {
                continue;
            }
            boolean check = false;
            //如果businessCheckModelList为空 或者不为空，但是至少有一个接管时间为空 那就用当前时间跟超时时间比较了
            if (CollectionUtils.isEmpty(businessCheckModelList)) {
                check = true;
            } else {
                long count = businessCheckModelList.stream().filter(m -> null == m.getJgwc()).count();
                if (count > 0) {
                    check = true;
                }
            }
            if (check) {
                LocalDateTime lmdl = lmModel.getLmdl();
                LocalDateTime deadline = lmdl.plusMinutes(time);
                if (LocalDateTime.now().compareTo(deadline) > 0) {
                    //更新发送状态
                    try {
                        TaskShipTask t = new TaskShipTask();
                        t.setMsgDljgFlag(1);
                        shipTaskService.update(t, new LambdaQueryWrapper<TaskShipTask>().eq(TaskShipTask::getId, model.getId()));

                        MsgInfo msgInfo = shipSend(model, "登轮→接管");
                        msgInfoList.add(msgInfo);
                    } catch (Exception e) {
                    }
                }

            }
        }
        if (CollectionUtils.isNotEmpty(msgInfoList)) {
            msgInfoService.saveMsgBatch(msgInfoList);//发消息
        }
    }

    /**
     * 装卸船 靠泊到首次起泵时间 超时
     */
    @Scheduled(fixedDelay = 2 * 60 * 1000)
    public void overtimeKBQB() {
        CfgWarnShip ws = warnShipService.getOne(null);
        if (null == ws || null == ws.getTime1() || ws.getTime1().intValue() <= 0) {
            return;
        }
        Integer time = ws.getTime1();
        List<MsgInfo> msgInfoList = new ArrayList<>();
        // 查询装卸船库里的未完成的LM任务 ，未发送报警的，并且operdetail操作过的
        Map<String, Object> params = new HashMap<>();
        params.put("kbqb", 1);
        List<TaskWarnModel> warnModelList = taskAllMapper.warnShipTaskList(params);
        for (TaskWarnModel model : warnModelList) {
            String operDetail = model.getOperDetail();
            TaskOperLMModel lmModel = JSON.parseObject(operDetail, TaskOperLMModel.class);
            List<BusinessCheckModel> businessCheckModelList = lmModel.getBusinessCheckModelList();
            if (null == lmModel.getKb())//如果靠泊时间都没有 那就不用判断先
            {
                continue;
            }
            boolean check = false;
            //如果businessCheckModelList为空 或者不为空，但是没有一个是有起泵时间的， 那就用当前时间跟超时时间比较了
            if (CollectionUtils.isEmpty(businessCheckModelList)) {
                check = true;
            } else {
                long count = businessCheckModelList.stream().filter(m -> null != m.getQb()).count();
                if (count == 0) {
                    check = true;
                }
            }
            if (check) {
                LocalDateTime kb = lmModel.getKb();
                LocalDateTime deadline = kb.plusMinutes(time);
                if (LocalDateTime.now().compareTo(deadline) > 0) {
                    //更新发送状态
                    try {
                        TaskShipTask t = new TaskShipTask();
                        t.setMsgKbqbFlag(1);
                        shipTaskService.update(t, new LambdaQueryWrapper<TaskShipTask>().eq(TaskShipTask::getId, model.getId()));

                        MsgInfo msgInfo = shipSend(model, "靠泊→启泵");
                        msgInfoList.add(msgInfo);
                    } catch (Exception e) {
                    }
                }

            }
        }
        if (CollectionUtils.isNotEmpty(msgInfoList)) {
            msgInfoService.saveMsgBatch(msgInfoList);//发消息
        }
    }

    private void startSend(TaskWarnModel model, List<MsgInfo> msgInfoList) {
        Set<Integer> userIds = new HashSet<>();
        SysUserEntity user = sysUserService.getTeamLeader(model.getTeamId());//组长
        if (null != user) {
            userIds.add(user.getUserId().intValue());
        }
        List<SysUserEntity> users = sysUserService.getDeptLeaderByTeam(model.getTeamId());//部门管理狗
        if (CollectionUtils.isNotEmpty(users)) {
            users.forEach(u -> userIds.add(u.getUserId().intValue()));
        }
        userIds.add(model.getOperUserId());
        String taskTypeName = taskSubService.getTaskTypeName(model.getPlan(), model.getPlanType(), model.getTaskType());
        String title = taskTypeName + ":开始任务超时!";
        TaskWarnMsgModel warnMsgModel = new TaskWarnMsgModel(model.getId(), model.getPlanName(), model.getTaskName(), model.getOperUserName());
        MsgInfo msgInfo = new MsgInfo("报警提示", "计划任务", title, JSON.toJSONString(warnMsgModel));
        msgInfo.setUserIdList(userIds);
        msgInfoList.add(msgInfo);
    }

    private void send(TaskWarnModel model, List<MsgInfo> msgInfoList) {
        Set<Integer> userIds = new HashSet<>();
        SysUserEntity user = sysUserService.getTeamLeader(model.getTeamId());//组长
        if (null != user) {
            userIds.add(user.getUserId().intValue());
        }
        List<SysUserEntity> users = sysUserService.getDeptLeaderByTeam(model.getTeamId());//部门管理狗
        if (CollectionUtils.isNotEmpty(users)) {
            users.forEach(u -> userIds.add(u.getUserId().intValue()));
        }
        userIds.add(model.getOperUserId());
        String taskTypeName = model.getTaskName();//taskSubService.getTaskTypeName(model.getPlan(), model.getPlanType(), model.getTaskType());
        String title = taskTypeName + ":超时未完成!";
        TaskWarnMsgModel warnMsgModel = new TaskWarnMsgModel(model.getId(), model.getPlanName(), model.getTaskName(), model.getOperUserName());
        MsgInfo msgInfo = new MsgInfo("报警提示", "计划任务", title, JSON.toJSONString(warnMsgModel));
        msgInfo.setUserIdList(userIds);
        msgInfoList.add(msgInfo);
    }

    private MsgInfo shipSend(TaskWarnModel model, String type) {
        Set<Integer> userIds = new HashSet<>();
        SysUserEntity user = sysUserService.getTeamLeader(model.getTeamId());
        if (null != user) {
            userIds.add(user.getUserId().intValue());
        }
        List<SysUserEntity> users = sysUserService.getDeptLeaderByTeam(model.getTeamId());//部门管理狗
        if (CollectionUtils.isNotEmpty(users)) {
            users.forEach(u -> userIds.add(u.getUserId().intValue()));
        }
        userIds.add(model.getOperUserId());
        String taskTypeName = taskSubService.getTaskTypeName(model.getPlan(), model.getPlanType(), model.getTaskType());
        String title = taskTypeName + ":" + type + ":超时未完成!";
        TaskWarnMsgModel warnMsgModel = new TaskWarnMsgModel(model.getId(), model.getPlanName(), model.getTaskName(), model.getOperUserName());
        warnMsgModel.setShipName(model.getShipName());
        MsgInfo msgInfo = new MsgInfo("报警提示", "计划任务", title, JSON.toJSONString(warnMsgModel));
        msgInfo.setUserIdList(userIds);

        return msgInfo;
    }

}
